set more off
clear all

local path0="C:\Dropbox\GeneticsProject (1)\REStat\round_accepted_replication_files\"

cd "`path0'data\ipums_1970"


use ipums1970, clear

* merge with the ethnic bridge for ethnic-country pairs

* MERGE USING FATHER'S BIRTHPLACE
joinby fbpld using fbpld, unmatched(master)
tab _merge 
drop _merge


* MERGE USING MOTHER'S BIRTHPLACE
joinby mbpld using mbpld, unmatched(master)
tab _merge 
drop _merge

gen USborn=(bpl<100) if bpl~=.

* merge with the data on individualism
joinby countrycode using ///
	"`path0'data\Culture_measures\idv_updated.dta" , unmatched(master)
	
tab _merge
drop _merge

*=======================================================================
* gen science_sector=(ind==746 | ind==787) if ind~=.
gen science_occupation=(occ==160 | occ==161 | occ==164 | occ==165 | ///
		occ==170 | occ==171 | occ==172 | occ==173 | occ==174 | occ==175 ///
		| occ==176 | occ==180 | occ==181 | occ==186 | occ==190 | occ==191 | occ==192 | occ==193 | occ==194) if occ~=.

gen science_occupationA=(occ>=130 & occ<200) | occ==121 if occ~=.

/*
160  	160  	Agricultural and Food Scientists
161 	161 	Biological Scientists
164 	164 	Conservation Scientists and Foresters
165 	165 	Medical Scientists
170 	170 	Astronomers and Physicists
171 	171 	Atmospheric and Space Scientists
172 	172 	Chemists and Materials Scientists
173 	173 	Not used
174 	174 	Environmental Scientists and Geoscientists
175 	175 	Not used
176 	176 	Physical Scientists, All Other
180 	180 	Economists
181 	181 	Market and Survey Researchers
182 	182 	Psychologists
183 	(See code 186) 	Sociologists
184 	184 	Urban and Regional Planners
185 	185 	Not used
186 	186 (Includes 183) 	Miscellaneous Social Scientists, Including Sociologists
190 	190 	Agricultural and Food Science Technicians
191 	191 	Biological Technicians
192 	192 	Chemical Technicians
193 	193 	Geological and Petroleum Technicians
194 	(See code 196) 	Nuclear Technicians
*/

compress

* keep only observatons with known ancestors
keep if idv~=.

*keep only employed individuals with non-missing occupation or industry
keep if occ~=. 

* keep only working age people
keep if age>=25 & age<=60

* drop individuals who attend a school
drop if school==2
drop school

keep if sex==1
compress

drop if countrycode=="USA"
quiet foreach var in ///
		AGO ALB  ARE ARG AUS AUT BEL BFA BGD BGR BRA BTN CAN ///
		CHE CHL CHN COL CRI CZE DNK DOM ECU EGY ESP EST ETH FIN ///
		FJI FRA GBR GER GHA GRC GTM HND HRV HUN IDN IND IRL IRN ///
		IRQ ISL ISR ITA JAM JOR JPN KEN KOR KWT LBN LBY LKA LTU LUX ///
		LVA MAR MEX MLT MOZ MWI MYS NAM NGA NLD NOR NPL NZL PAK PAN ///
		PER PHL POL PRT ROM RUS SAU SCG SEN SLE SLV SVK SVN SWE ///
		SYR THA TTO TUR TWN TZA UKR URY VEN VNM ZAF ZMB  ///	
 {

gen byte e_`var'=(countrycode=="`var'")
}

compress e_*

save step300, replace

